package com.framework.myandroid.eventbus

import androidx.annotation.Nullable
import com.framework.myandroid.base.BaseJson
import org.greenrobot.eventbus.EventBus

object EventBusHelper {
    const val RESPONSE_NULL = -11 //返回的BaseJson为空
    const val LOGIN_SUCCESS = 66 //登录成功
    const val LOGIN_STATUS_ERROR = -99
    const val UPDATA_MY_INFO_SUCCESS = 71
    const val NO_MORE_DATA = 2004 //沒有更多數據
    const val LOCATION_SUCCESS = 661 //定位成功
    const val HIDE_PERSONAL_FRAGMENT = 401
    const val HIDE_PERSON_FRAGMENT = 402
    const val SAVE_PERSON_FRAGMENT = 407
    const val SHOW_EDIT_FRAGMENT = 403
    const val HIDE_EDIT_FRAGMENT = 404
    const val SAVE_EDIT_FRAGMENT = 406
    const val GOTO_COLLECTION = 405
    const val PERSONNEW_INDEX_NORMAL = 998 //量体控件跳转定位
    const val DATA_PERSON_CHANGE_IMG = 997 //刷新图片跳转
    const val DATA_PERSON_CHANGE_SIZE = 999 //刷新图片跳转
    const val SETTING_CLOTHES_ID = 996 //点击跳转号型
    const val REFRESH_UI = 995 //点击跳转号型

    /**
     * janus收到event内容为unpublished的信息
     */
    const val JANUS_RECEIVE_UNPUBLISHED = 70

    /**
     * 视频已从服务器终止
     */
    const val JANUS_RECEIVE_HANG_UP = 664
    private const val TAG = "EventBusHelper"
    fun sendEventBusMsg(code: Int?, msg: String?) {
        EventBus.getDefault().post(EventBusMessage(code, msg))
    }

    fun sendEventBusMsg(code: Int, msg: String?, time: Long, type: Int) {
        EventBus.getDefault().post(EventBusMessage(code, msg, time, type))
    }


    fun sendEventBusMsg(msg: String?) {
        EventBus.getDefault().post(EventBusMessage(msg))
    }

    fun handleBaseJson(@Nullable baseJson: BaseJson?) {
        if (baseJson != null) {
            if (!(baseJson.code !== 0 && baseJson.code !== 201)) {
            } else {
                sendEventBusMsg(baseJson.code, baseJson.msg)
            }
        } else {
            sendEventBusMsg(RESPONSE_NULL, "")
        }
    }
}
